package editors.gui;
import graphics.system.Color;
import graphics.system.GLTools;
import tools.Help;
import tools.Point;
public class GuiButton extends GuiObject {
	private String text;
	private float cd;
	public GuiButton(Point pos, float width, String text) {
		super();
		this.rect = new Rect(pos.add(new Point(width / 2, -GuiSettings.LINEHEIGHT / 2)), width, GuiSettings.LINEHEIGHT);
		this.text = text;
		cd = 0;
	}
	@Override
	public boolean isClicked() {
		return clicked;
	}
	@Override
	public boolean checkClick(Point mp) {
		this.clicked = rect.isIn(mp);
		if (clicked)
			cd = 10;
		return clicked;
	}
	public void makeSelected() {
		if (cd < 5)
			cd = 5;
	}
	@Override
	public void draw() {
		Point s = rect.getTopLeft();
		s.sAdd(new Point(2, -GuiSettings.FONTADJUST));
		Color c = Color.blend(GuiSettings.BUTTON_OFF_COL, GuiSettings.BUTTON_ON_COL, cd * 0.1f);
		rect.draw(c);
		GLTools.drawText(s, text, GuiSettings.TEXT_COL, GuiSettings.FONTSIZE);
		if (cd > 0)
			cd -= 0.2f;
		else
			cd = 0;
	}
}
